/*
 * @Author: '浪川' '1214391613@qq.com'
 * @Date: 2025-07-05 16:06:20
 * @LastEditors: '浪川' '1214391613@qq.com'
 * @LastEditTime: 2025-08-20 15:44:38
 * @FilePath: \passiflora-edulis-sims\src\stores\wordsearch-store.ts
 * @Description: 单词搜索 的 状态管理
 *
 * Copyright (c) 2025 by '1214391613@qq.com', All Rights Reserved.
 */
import { defineStore, acceptHMRUpdate } from 'pinia'
import { v1_wordsearch } from 'src/boot/PuzzleApi'
import type { IWordSearchFeatures } from 'src/interfaces/IAdvancedPuzzle'
import type { v1IWordSearchReq } from 'src/interfaces/Requests/v1IPuzzleRes'
import type { IWordSearchRes } from 'src/interfaces/Responses/Game'

export const useWordSearchIStore = defineStore('WordSearch', {
  state: (): IWordSearchFeatures => ({
    size: 13,
    words_legend: {
      text: 'Word List',
      font: {
        font_name: '',
        font_size: 25,
        font_color: '#000000',
      },
      text_align: 'center',
      vertical_align: 'middle',
      offet_x: 0,
      offet_y: 0,
    },
    directions: ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'],
    solution: {
      category: 'Border',
      stroke: {
        type: 'solid',
        color: '#000000',
        style: {
          strokeWidth: 1,
        },
      },
    },
    level: 3,
  }),

  getters: {
    v1_wordsearch_reqData(): v1IWordSearchReq {
      const wordsearch_req: v1IWordSearchReq = {
        level: this.level,
        directions: this.directions.join(','),
        size: this.size,
        words: '',
      }

      return wordsearch_req
    },
    solution_categorys(): string[] {
      return ['Border', 'Highlight']
    },
  },

  actions: {
    async v1_wordsearch(words: string[]): Promise<IWordSearchRes> {
      const wordsearch_req_data = this.v1_wordsearch_reqData
      wordsearch_req_data.words = words.join(',')
      const res = await v1_wordsearch(wordsearch_req_data)
      if (res.status_code == 200) {
        return res.data
      } else {
        return { answers: {}, puzzle_array: [[]] }
      }
    },
  },
})

if (import.meta.hot) {
  import.meta.hot.accept(acceptHMRUpdate(useWordSearchIStore, import.meta.hot))
}
